<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Created by CodeTlan.
 * User: Ing. Miguel Salas
 * Date: 3/4/12
 * Time: 9:28 PM
 */
class Users extends CT_Controller
{
    function __construct(){
        parent::__construct();
        $this->load->model('user', 'dao');
    }

    function logout(){
        $this->session->logout();
        echo "{success:true}";
    }

    function add(){
        $data['usuario_k']=$this->input->post('usuario_k');
        $data['password']=md5(md5($this->input->post('password')));
        $data['nombre']=$this->input->post('nombre');
        $data['apellidos']=$this->input->post('apellidos');
        $data['rol_k']=$this->input->post('rol_k');
        $data['activo']=1;
        $data['estatus']=1;
        echo $this->_add($data);
    }

    function edit(){
        $data=(array) json_decode($this->input->post("mod"));
        echo $this->_edit($data,array('usuario_k' => $this->input->post('usuario_k')));
    }

    function active()
    {
        echo $this->_edit(array('activo' => $this->input->post('activo')), array('usuario_k' => $this->input->post('usuario_k')));
    }

    /*function delete()
    {
        echo $this->_edit(array('estatus' => 0), array('usuario_k' => $this->input->post('usuario_k')));
    }*/

    function find(){
        $result=$this->dao->find('
            U.usuario_k,
            U.nombre,
            U.apellidos,
            U.rol_k,
            R.titulo as rol,
            U.activo,
            U.logins,
            U.last_login
        ','',$this->input->post('start'),NUM_ROWS);
        echo $this->getSuccess($result);
    }

    function pass(){
        $data["password"]=md5(md5($this->input->post("password")));
        echo $this->_edit($data,array('usuario_k' => $this->input->post('usuario_k')));
    }
}
